package top.infopub.mgr.bpa.web;


import com.github.pagehelper.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import top.infopub.mgr.bpa.domain.ContractLedgerDomain;
import top.infopub.mgr.bpa.service.ContractNegService;
import top.infopub.mgr.bpa.vo.ContractManageVo;
import top.infopub.mgr.common.page.ParamPage;
import top.infopub.mgr.common.vo.RspVo;
import top.infopub.mgr.mkt.service.MarketManageService;
import top.infopub.model.hr.OrgInfo;
import top.infopub.model.hr.StaffInfo;
import top.infopub.security.util.SessionUserUtils;
import top.infopub.security.vo.AuthorizationVO;

import javax.servlet.http.HttpServletRequest;
import java.text.ParseException;
import java.util.List;

/**
 * 合同台账管理
 * @author TSZ
 * @version
 * @see
 * @since
 */
@Controller
@RequestMapping("/business")
public class BusinessContractController {

    @Autowired
    private MarketManageService marketManageService;
    @Autowired
    private ContractNegService contractNegService;

    /**
     * 合同台账列表
     * @return
     */
    @RequestMapping("/list")
    public String list(HttpServletRequest request) {
        //获取登录人员信息
        AuthorizationVO vo = SessionUserUtils.getSessionAttributeForUserDtl();
        //查询区域公司列表
        List<OrgInfo> orgInfoList = marketManageService.queryOrgInfoByAuthUserId(vo);
        request.setAttribute("orgInfoList", orgInfoList);
        //查询营销人员列表
        List<StaffInfo> staffInfoList = marketManageService.queryStaffInfoByAuthUserId(vo);
        request.setAttribute("staffInfoList", staffInfoList);
        return "bpa/lay-businessContract-list";
    }


    /**
     * 分包合同台账
     *
     * @return
     */
    @RequestMapping("/selectByLedger")
    @ResponseBody
    public RspVo<ContractLedgerDomain> selectByLedger(ContractManageVo contractManageVo, ParamPage paramPage) throws ParseException {
        Page<ContractLedgerDomain> page = new Page<ContractLedgerDomain>();
        page.setPageNum(paramPage.getPage());
        page.setPageSize(paramPage.getLimit());
        //查询时，结束日期增加一天
        if (contractManageVo.getEndDate() != null) {
            contractManageVo.setEndDate(top.infopub.mgr.util.DateUtils.addDays(contractManageVo.getEndDate(), 1));
        }
        page = contractNegService.selectByLedger(page, contractManageVo);
        return RspVo.getSuccessResponse(page.getTotal(), page.getResult());
    }

    /**
     *  下拉列表
     * @return
     */
    @RequestMapping("/businessList")
    public String bidManageList(HttpServletRequest request) {
        //获取登录人员信息
        AuthorizationVO vo = SessionUserUtils.getSessionAttributeForUserDtl();
        //查询区域公司列表
        List<OrgInfo> orgInfoList = marketManageService.queryOrgInfoByAuthUserId(vo);
        request.setAttribute("orgInfoList", orgInfoList);
        //查询营销人员列表
        List<StaffInfo> staffInfoList = marketManageService.queryStaffInfoByAuthUserId(vo);
        request.setAttribute("staffInfoList", staffInfoList);
        return "bpa/lay-businessContract-list";
    }

}
